package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入你要新增图书的书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                System.out.println("已经存在这本书了");
                System.out.println(book);
                return;
            }
        }
        //插入一本书到最后
        System.out.println("请输入你要新增图书的作者");
        String author=scanner.nextLine();
        System.out.println("请输入你要新增图书的价格");
        int price=scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入你要新增图书的类型");
        String type=scanner.nextLine();
        Book book=new Book(name,author,price,type);
        bookList.setBook(currentSize,book);
        bookList.setUsedSize(currentSize+1);
        System.out.println("新增成功");


    }
}
